<template>
  <div class="jingtiao tou">
    <div v-if="!inline" class="content_title" style="cursor: pointer" @click="showDialogTech">
      <span class="content_text">头并</span>
      <img class="content_img" src="@/assets/img/chart/jingtiao.png" alt="" srcset="" />
    </div>
    <div class="jingtiao_body">
      <div class="jingtiaoCol">
        <div v-for="(item, index) in jingtiaoData.jingtiaoCol1Data" :key="index + 's'" class="jingtiao_item">
          <div v-if="index == 0">
            <div class="dongli2" @click="clickHandleDl('jingtiaoT_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div v-if="index == jingtiaoData.jingtiaoCol1Data.length - 1">
            <div class="dongli" @click="clickHandleDl('jingtiaoT_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle('jingtiao', item)">
            <jingtiaol :data="item"></jingtiaol>
          </div>
        </div>
      </div>
    </div>
    <!-- 并条弹窗控件 -->
    <jingtiaoDialog v-if="showModal" :defaultData="data1" ref="jingtiaoDialog" />
    <!-- 粗纱弹窗控件 -->
    <!-- <cushaDialog ref="cushaDialog2" /> -->
    <!-- 动力柜弹窗控件 -->
    <dongliDialog v-if="showDongliModal" ref="dongliDialog"></dongliDialog>
    <!-- 并条工艺详情 -->
    <jingtiao-dialog-tech v-if="techShow" ref="jingtiaoDialogTech"></jingtiao-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_dongli/index'
import jingtiaoDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_jingtiao/index'
// import cushaDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_cusha/index'
import jingtiaol from '@/views/monitorCenter/workChart/components/qcs/jingtiao_l'
import jingtiaor from '@/views/monitorCenter/workChart/components/qcs/jingtiao_r'
// import cusha from '@/views/monitorCenter/workChart/components/qcs/cusha'
import COMMON from '@/utils/common'
import dongLiMenu from '@/assets/data/dongli.json'
import dongliItem from '@/assets/data/dongliItem.json'
export default {
  name: 'JingTiao',
  props: {
    msg: String,
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: {
    dongliDialog,
    jingtiaol,
    jingtiaor,
    jingtiaoDialog
    // cushaDialog,
    // cusha
  },
  data() {
    return {
      jingtiaoData: {
        // 1-12
        jingtiaoCol1Data: [],
        // 1-12
        jingtiaoCol2Data: []
      },
      cushaData: {
        // 15-16
        cushaDataRow2Data: []
      },
      dongLiMenu: {},
      dongLiItem: {},
      showModal: false,
      showDongliModal: false,
      techShow: false,
      data1: {}
    }
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.jingtiaoDialogTech = require('@/views/monitorCenter/workChart/components/qcs/dialogBig/dialog_jingtiao_tech/index').default
  },
  created() {
    this.dongLiMenu = dongLiMenu
    this.dongLiItem = dongliItem
  },
  computed: {
    bingTiaoGroupState() {
      let result
      if (this.$store.state.socketData.length != 0) {
        result = this.$store.state.socketData.filter(item => item.workshop == this.$store.state.workshopNo)
        result = result[0].dsDeviceRealTimeStatusListDrawingM
      }
      return result
    },
    txcsomlGroupState() {
      let result
      if (this.$store.state.socketData.length != 0) {
        result = this.$store.state.socketData.filter(item => item.workshop == this.$store.state.workshopNo)
        result = result[0].dsDeviceRealTimeStatusListRove
      }
      return result
    }
  },
  watch: {
    bingTiaoGroupState: {
      immediate: true,
      handler(val) {
        if (val) {
          this.jingtiaoData.jingtiaoCol1Data = val
        }
      }
    },
    txcsomlGroupState: {
      immediate: true,
      handler(val) {
        if (val) {
          this.cushaData.cushaDataRow2Data = COMMON.devSnFilter(val, 15, 16)
        }
      }
    }
  },
  methods: {
    closeHandle() {
      this.showModal = false
      this.showDongliModal = false
    },
    clickHandle(flag, item) {
      switch (flag) {
        case 'cusha':
          this.$parent.getInfoByDevSn('TXCSOML', item.deviceNo)
          this.$refs.cushaDialog2.showDialog(item)
          break
        case 'jingtiao':
          this.data1 = item
          this.data1.classes = this.$store.state.workshopData.shiftPreSpinTxt
          this.showModal = true
          break
      }
    },
    clickHandleDl(item, deviceName) {
      this.showDongliModal = true
      var dialogData = this.dongLiItem[`${item}_${this.$store.state.workshopNo}`]
      console.log('dialogData', item + '_' + this.$store.state.workshopNo)
      this.$nextTick(() => {
        this.$refs.dongliDialog.showDialog(dialogData)
      })
    },
    showDialogTech() {
      this.techShow = true
    },
    closeDialogTech() {
      this.techShow = false
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/workshop.less';
</style>
